package token

import "context"

const (
	AppName = "token"
)

type Service interface {
	// 令牌颁发
	IssueToken(ctx context.Context, req *IssueTokenRequest) (*Token, error)

	// 令牌校验
	ValidateToken(ctx context.Context, req *ValidateTokenRequest) (*Token, error)

	// 令牌撤销
	RevolkToken(ctx context.Context, req *RevolkTokenRequest) (*Token, error)
}

func NewIssueTokenRequest(username, password string) *IssueTokenRequest {
	return &IssueTokenRequest{
		Username: username,
		Password: password,
		IsMember: false,
	}
}

type IssueTokenRequest struct {
	Username string `json:"username"`
	Password string `json:"password"`
	// 记住我
	IsMember bool `json:"is_member"`
}
type RevolkTokenRequest struct {
	AccessToken string
	// 撤销时应该知道正确的刷新Token
	RefreshToken string
}

func NewRevolkTokenRequest(accessToken, refreshToken string) *RevolkTokenRequest {
	return &RevolkTokenRequest{
		AccessToken:  accessToken,
		RefreshToken: refreshToken,
	}
}

type ValidateTokenRequest struct {
	AccessToken string
}

func NewValidateTokenRequest(accessToken string) *ValidateTokenRequest {
	return &ValidateTokenRequest{
		AccessToken: accessToken,
	}
}
